/**
 * 
 * merge level=48
 * 
 * 一个模块的总panel,包括导航，toolbar,listgrid,detail,etc.
 */

Ext.define('Jfok.module.ModulePanel', {
			extend : 'Ext.panel.Panel',
			alias : 'widget.modulepanel',
			frame : false,
			border : false,
			layout : 'border',
			requires : ['Jfok.module.ToolBar', 'Jfok.module.ChildToolBar',
					'Jfok.module.factory.ModelFactory', 'Jfok.module.Grid',
					'Jfok.module.Detail', 'Jfok.module.navigate.Navigate'],
			module : null,
			// 是否显示导航栏
			collapseNavigate : false,
			// 是否允许有导航栏
			enableNavigate : true,
			param : {},
			config : {
				parentFilter : null,
				gridType : 'normal'
			},
			initComponent : function() {

				this.margin = Ext.themeName === 'neptune' ? '0 0 0 0' : '1 1 1 1';
				Ext.apply(this, this.param);
				console.log(this.module);
				this.store = Ext.create('Jfok.module.GridStore', {
							module : this.module,
							modulePanel : this
						});
				this.moduleName = this.module.tf_moduleName;
				var grid_detail = [{
							region : 'center',
							xtype : 'modulegrid',
							modulePanel : this,
							parentFilter : this.parentFilter,
							gridType : this.gridType
						}, {
							region : 'east',
							xtype : 'recorddetail',
							modulePanel : this,
							width : 400,
							title : '记录明细',
							split : true,
							collapsible : true,
							collapsed : true,
							collapseMode : 'mini'
						}];
				if (this.moduleName == '_Addition') {
					this.store.pageSize = 100;
					this.items = [{
								xtype : 'attachmenttabpanel',
								region : 'center',
								store : this.store,
								grid_detail : grid_detail
							}]
				} else
					this.items = grid_detail;
				if (this.enableNavigate)
					if (this.module.moduleGridNavigates
							&& this.module.moduleGridNavigates.length > 0) {
						this.items.push({
							region : 'west',
							width : 258,
							title : '导航',
							xtype : 'modulenavigate',
							defaultNavigateValues : this.param
									? this.param.defaultNavigateValues
									: null,
							parentFilter : this.parentFilter,
							module : this.module,
							split : true,
							collapsed : this.collapseNavigate,
							collapsible : true,
							collapseMode : 'mini'
								// , collapsed : (this.parentFilter) ? true : false

							})
					}

				this.callParent(arguments);
			},

			listeners : {
				render : function(modulepanel) {
					// console.log(modulepanel);
				}
			},

			applyParentFilter : function(fp) {
				this.parentFilter = fp;
				this.down('modulegrid').setParentFilter(fp);
				if (this.down('modulenavigate'))
					this.down('modulenavigate').setParentFilter(fp);
			},

			refreshNavigate : function() {
				var tool = this.down('modulenavigate tool[type=refresh]');
				if (tool)
					tool.fireEvent('click', tool);
			},

			changeParentFilter : function(parentModuleName, pid, ptitle, navigates) {
				var pm = Jfok.modules.getModuleInfoWithName(parentModuleName);
				var pf = {
					moduleId : pm.tf_moduleId,
					moduleName : parentModuleName,
					tableAsName : pm.tableAsName,
					primarykey : pm.tf_primaryKey,
					fieldtitle : pm.tf_title,
					equalsValue : pid,
					equalsMethod : null,
					text : ptitle,
					isCodeLevel : pm.codeLevel
				};
				this.parentFilter = pf;
				this.down('modulegrid').changeParentFilter(pf, navigates);
				if (this.down('modulenavigate'))
					this.down('modulenavigate').changeParentFilter(pf, navigates);

			}

		})
